##位置代理组件,主要解决物理刚体,普通区域单位无法复用代码的问题
class_name MovementPhysic2D extends CharacterBody2D
##持有这个组件的单位
@export var owner_unit : Unit
##组件类型
@export var component_type_list : Array[Enums.COMPONENT_TYPE] = [Enums.COMPONENT_TYPE.MOVEMENT_PROXY]
#移动转向力
var force : Vector2 = Vector2.ZERO
#被动移动向量
var effect_velocity : Vector2 = Vector2.ZERO
#移动向量
var move_velocity : Vector2

@export var attribute : Attribute

func _unit_ready():
	if !attribute:
		attribute = owner_unit.get_first_component_by_type(Enums.COMPONENT_TYPE.ATTRIBUTE)
	top_level = true
	global_position = owner_unit.global_position

func _physics_process(delta):
	move_velocity += force.limit_length(attribute.max_steering_force)
	move_velocity = move_velocity.limit_length(attribute.max_speed)
	velocity = move_velocity + effect_velocity
	move_and_slide()
	owner_unit.global_position = global_position
	force = Vector2.ZERO

func stop_now():
	move_velocity = Vector2.ZERO
	force = Vector2.ZERO
